package com.gisocn.onemap.ui.fragment;

import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Intent;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.TextView;
import androidx.core.content.ContextCompat;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;
import com.bumptech.glide.Glide;
import com.gisocn.onemap.base.BaseFragment;
import com.gisocn.onemap.base.CommonAdapter;
import com.gisocn.onemap.base.Constant;
import com.gisocn.onemap.base.MultiItemTypeAdapter;
import com.gisocn.onemap.base.ViewHolder;
import com.gisocn.onemap.event.MessageEvent;
import com.gisocn.onemap.interfaces.DownLoadListener;
import com.gisocn.onemap.model.AppConfig;
import com.gisocn.onemap.model.DownLoadFileInfo;
import com.gisocn.onemap.model.GetDirectoryData;
import com.gisocn.onemap.presenter.PlanDataBasePresent;
import com.gisocn.onemap.sgzx.R;
import com.gisocn.onemap.ui.activity.FileBrowseActivity;
import com.gisocn.onemap.ui.activity.MainActivity;
import com.gisocn.onemap.utils.L;
import com.gisocn.onemap.utils.SpUtils;
import com.gisocn.onemap.view.PlanDataBaseView;
import com.gisocn.onemap.widget.NumberProgressBar;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.tencent.smtt.sdk.TbsVideoCacheTask;
import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import kotlin.text.Typography;
import org.greenrobot.eventbus.EventBus;

/* loaded from: classes2.dex */
public class PlanDataBaseFragment extends BaseFragment<PlanDataBasePresent> implements PlanDataBaseView {
    private AppConfig appConfig;
    String deviceId;
    private Dialog dialog;
    private String dirId;
    private String dirPath;
    private PopupWindow dirsPopupWindow;
    private View dirsView;
    CommonAdapter fileAdapter;
    CommonAdapter firstAdapter;
    GetDirectoryData getDirectoryData;
    private int index;
    @BindView(R.id.iv_back)
    ImageView ivBack;
    private NumberProgressBar numberProgressBar;
    @BindView(R.id.recycle_plan_first)
    RecyclerView recyclePlanFirst;
    @BindView(R.id.recycle_plan_second)
    RecyclerView recyclePlanSecond;
    CommonAdapter secondAdapter;
    private TextView tvFileName;
    private TextView tvIndex;
    private TextView tvOff;
    @BindView(R.id.tv_title)
    TextView tvTitle;
    Unbinder unbinder;
    String userId;
    int width;
    private ArrayList<GetDirectoryData.DataBean.DirsBean> dirList = new ArrayList<>();
    private ArrayList<GetDirectoryData.DataBean.FoldersBean> folderList = new ArrayList<>();
    private ArrayList<GetDirectoryData.DataBean.FilesBean> fileTextList = new ArrayList<>();
    private ArrayList<GetDirectoryData.DataBean.FilesBean> fileImageList = new ArrayList<>();
    private ArrayList<GetDirectoryData.DataBean.FilesBean> fileAttachmentList = new ArrayList<>();
    private final ArrayList<GetDirectoryData.DataBean.FilesBean> fileList = new ArrayList<>();
    private ArrayList<DownLoadFileInfo> allDownLoadList = new ArrayList<>();
    private ArrayList<String> filesLocaList = new ArrayList<>();
    private ArrayList<GetDirectoryData.DataBean.FoldersBean> collectFolders = new ArrayList<>();
    private int fileType = 0;
    int secondIndex = -1;
    Handler handler = new Handler() { // from class: com.gisocn.onemap.ui.fragment.PlanDataBaseFragment.6
        @Override // android.os.Handler
        public void handleMessage(Message message) {
            super.handleMessage(message);
            int i = message.what;
            if (i == 1) {
                PlanDataBaseFragment.this.fileAdapter.notifyDataSetChanged();
            } else if (i == 2) {
                if (PlanDataBaseFragment.this.numberProgressBar != null) {
                    PlanDataBaseFragment.this.numberProgressBar.setProgress(message.arg1);
                    if (message.arg1 == 100 && message.arg2 == 1) {
                        PlanDataBaseFragment.this.dialog.dismiss();
                    }
                }
            } else if (i != 3) {
            } else {
                PlanDataBaseFragment.this.fileAdapter.notifyDataSetChanged();
                if (PlanDataBaseFragment.this.index >= PlanDataBaseFragment.this.allDownLoadList.size() - 1) {
                    PlanDataBaseFragment.this.dialog.dismiss();
                    return;
                }
                PlanDataBaseFragment.access$1108(PlanDataBaseFragment.this);
                PlanDataBaseFragment planDataBaseFragment = PlanDataBaseFragment.this;
                planDataBaseFragment.downLoadFile(((DownLoadFileInfo) planDataBaseFragment.allDownLoadList.get(PlanDataBaseFragment.this.index)).getFileUrl(), ((DownLoadFileInfo) PlanDataBaseFragment.this.allDownLoadList.get(PlanDataBaseFragment.this.index)).getFileName(), ((DownLoadFileInfo) PlanDataBaseFragment.this.allDownLoadList.get(PlanDataBaseFragment.this.index)).getLocalPath(), true, PlanDataBaseFragment.this.index);
            }
        }
    };

    @Override // com.gisocn.onemap.view.PlanDataBaseView
    public void fail(String str) {
    }

    static /* synthetic */ int access$1108(PlanDataBaseFragment planDataBaseFragment) {
        int i = planDataBaseFragment.index;
        planDataBaseFragment.index = i + 1;
        return i;
    }

    @Override // com.gisocn.onemap.base.BaseFragment, androidx.fragment.app.Fragment
    public View onCreateView(LayoutInflater layoutInflater, ViewGroup viewGroup, Bundle bundle) {
        View inflate = layoutInflater.inflate(R.layout.fragment_plan_database, viewGroup, false);
        this.unbinder = ButterKnife.bind(this, inflate);
        this.tvTitle.setText(R.string.planning_database);
        this.width = getResources().getDisplayMetrics().widthPixels;
        return inflate;
    }

    @Override // com.gisocn.onemap.base.BaseFragment
    protected void initData() {
        ArrayList arrayList = (ArrayList) new Gson().fromJson(SpUtils.get(getActivity(), "folderCollect", "").toString(), new TypeToken<List<GetDirectoryData.DataBean.FoldersBean>>() { // from class: com.gisocn.onemap.ui.fragment.PlanDataBaseFragment.1
        }.getType());
        if (arrayList != null) {
            this.collectFolders.addAll(arrayList);
        }
        L.e("总收藏" + this.collectFolders.size());
        this.appConfig = ((MainActivity) getActivity()).getAppConfig();
        this.presenter = createPresenter();
        this.userId = SpUtils.get(getActivity(), "userId", "") + "";
        this.deviceId = SpUtils.get(getActivity(), "deviceId", "") + "";
        this.recyclePlanFirst.setLayoutManager(new LinearLayoutManager(getActivity()));
        this.recyclePlanSecond.setLayoutManager(new LinearLayoutManager(getActivity()));
        this.recyclePlanFirst.setVisibility(0);
        this.recyclePlanSecond.setVisibility(8);
        CommonAdapter<GetDirectoryData.DataBean.DirsBean> commonAdapter = new CommonAdapter<GetDirectoryData.DataBean.DirsBean>(getActivity(), R.layout.item_plan_database_first, this.dirList) { // from class: com.gisocn.onemap.ui.fragment.PlanDataBaseFragment.2
            /* JADX INFO: Access modifiers changed from: protected */
            @Override // com.gisocn.onemap.base.CommonAdapter
            public void convert(ViewHolder viewHolder, GetDirectoryData.DataBean.DirsBean dirsBean, int i) {
                if (i == PlanDataBaseFragment.this.dirList.size() - 1) {
                    viewHolder.getView(R.id.view_line).setVisibility(8);
                }
                viewHolder.setText(R.id.tv_dirs, ((GetDirectoryData.DataBean.DirsBean) PlanDataBaseFragment.this.dirList.get(i)).getNAME());
            }
        };
        this.firstAdapter = commonAdapter;
        commonAdapter.setOnItemClickListener(new MultiItemTypeAdapter.OnItemClickListener() { // from class: com.gisocn.onemap.ui.fragment.PlanDataBaseFragment.3
            @Override // com.gisocn.onemap.base.MultiItemTypeAdapter.OnItemClickListener
            public boolean onItemLongClick(View view, RecyclerView.ViewHolder viewHolder, int i) {
                return false;
            }

            @Override // com.gisocn.onemap.base.MultiItemTypeAdapter.OnItemClickListener
            public void onItemClick(View view, RecyclerView.ViewHolder viewHolder, int i) {
                if (PlanDataBaseFragment.this.dirsPopupWindow != null) {
                    PlanDataBaseFragment.this.dirsPopupWindow.dismiss();
                }
                PlanDataBaseFragment planDataBaseFragment = PlanDataBaseFragment.this;
                planDataBaseFragment.dirId = ((GetDirectoryData.DataBean.DirsBean) planDataBaseFragment.dirList.get(i)).getDIR_ID();
                PlanDataBaseFragment planDataBaseFragment2 = PlanDataBaseFragment.this;
                planDataBaseFragment2.dirPath = ((GetDirectoryData.DataBean.DirsBean) planDataBaseFragment2.dirList.get(i)).getNAME();
                PlanDataBaseFragment.this.ivBack.setVisibility(0);
                PlanDataBaseFragment.this.folderList.clear();
                L.e("setOnItemClickListener___" + i);
                for (GetDirectoryData.DataBean.FoldersBean foldersBean : PlanDataBaseFragment.this.getDirectoryData.getData().getFolders()) {
                    if (((GetDirectoryData.DataBean.DirsBean) PlanDataBaseFragment.this.dirList.get(i)).getDIR_ID().equals(foldersBean.getDIR_ID())) {
                        Iterator it = PlanDataBaseFragment.this.collectFolders.iterator();
                        while (true) {
                            if (it.hasNext()) {
                                if (((GetDirectoryData.DataBean.FoldersBean) it.next()).getCNUM().equals(foldersBean.getCNUM())) {
                                    foldersBean.setCollect(true);
                                    break;
                                }
                            } else {
                                break;
                            }
                        }
                        PlanDataBaseFragment.this.folderList.add(foldersBean);
                    }
                }
                PlanDataBaseFragment.this.recyclePlanFirst.setVisibility(8);
                PlanDataBaseFragment.this.recyclePlanSecond.setVisibility(0);
                PlanDataBaseFragment.this.secondAdapter.notifyDataSetChanged();
            }
        });
        CommonAdapter<GetDirectoryData.DataBean.FoldersBean> commonAdapter2 = new CommonAdapter<GetDirectoryData.DataBean.FoldersBean>(getActivity(), R.layout.item_plan_database_second, this.folderList) { // from class: com.gisocn.onemap.ui.fragment.PlanDataBaseFragment.4
            /* JADX INFO: Access modifiers changed from: protected */
            @Override // com.gisocn.onemap.base.CommonAdapter
            public void convert(ViewHolder viewHolder, GetDirectoryData.DataBean.FoldersBean foldersBean, final int i) {
                viewHolder.setText(R.id.tv_folders, ((GetDirectoryData.DataBean.FoldersBean) PlanDataBaseFragment.this.folderList.get(i)).getNAME());
                Glide.with(PlanDataBaseFragment.this.getActivity()).load(Integer.valueOf(((GetDirectoryData.DataBean.FoldersBean) PlanDataBaseFragment.this.folderList.get(i)).isCollect() ? R.mipmap.icon_collect : R.mipmap.icon_uncollect)).into((ImageView) viewHolder.getView(R.id.iv_collect));
                if (PlanDataBaseFragment.this.secondIndex == i) {
                    viewHolder.itemView.setBackgroundColor(ContextCompat.getColor(PlanDataBaseFragment.this.getActivity(), R.color.colorGray));
                } else {
                    viewHolder.itemView.setBackgroundColor(ContextCompat.getColor(PlanDataBaseFragment.this.getActivity(), R.color.white));
                }
                viewHolder.setOnClickListener(R.id.iv_collect, new View.OnClickListener() { // from class: com.gisocn.onemap.ui.fragment.PlanDataBaseFragment.4.1
                    @Override // android.view.View.OnClickListener
                    public void onClick(View view) {
                        if (((GetDirectoryData.DataBean.FoldersBean) PlanDataBaseFragment.this.folderList.get(i)).isCollect()) {
                            Iterator it = PlanDataBaseFragment.this.collectFolders.iterator();
                            while (true) {
                                if (!it.hasNext()) {
                                    break;
                                }
                                GetDirectoryData.DataBean.FoldersBean foldersBean2 = (GetDirectoryData.DataBean.FoldersBean) it.next();
                                if (foldersBean2.getCNUM().equals(((GetDirectoryData.DataBean.FoldersBean) PlanDataBaseFragment.this.folderList.get(i)).getCNUM())) {
                                    PlanDataBaseFragment.this.collectFolders.remove(foldersBean2);
                                    break;
                                }
                            }
                            L.e("取消收藏" + PlanDataBaseFragment.this.collectFolders.size());
                        } else {
                            if (!PlanDataBaseFragment.this.collectFolders.contains(PlanDataBaseFragment.this.folderList.get(i))) {
                                PlanDataBaseFragment.this.collectFolders.add(PlanDataBaseFragment.this.folderList.get(i));
                            }
                            L.e("收藏" + PlanDataBaseFragment.this.collectFolders.size());
                        }
                        ((GetDirectoryData.DataBean.FoldersBean) PlanDataBaseFragment.this.folderList.get(i)).setCollect(!((GetDirectoryData.DataBean.FoldersBean) PlanDataBaseFragment.this.folderList.get(i)).isCollect());
                        PlanDataBaseFragment.this.secondAdapter.notifyDataSetChanged();
                        SpUtils.put(PlanDataBaseFragment.this.getActivity(), "folderCollect", new Gson().toJson(PlanDataBaseFragment.this.collectFolders));
                        EventBus.getDefault().post(new MessageEvent(Constant.MESSAGE_EVENT_UPDATA_COLLECTION_BUILD_FRUIT));
                    }
                });
            }
        };
        this.secondAdapter = commonAdapter2;
        commonAdapter2.setOnItemClickListener(new MultiItemTypeAdapter.OnItemClickListener() { // from class: com.gisocn.onemap.ui.fragment.PlanDataBaseFragment.5
            @Override // com.gisocn.onemap.base.MultiItemTypeAdapter.OnItemClickListener
            public boolean onItemLongClick(View view, RecyclerView.ViewHolder viewHolder, int i) {
                return false;
            }

            @Override // com.gisocn.onemap.base.MultiItemTypeAdapter.OnItemClickListener
            public void onItemClick(View view, RecyclerView.ViewHolder viewHolder, int i) {
                PlanDataBaseFragment.this.secondIndex = i;
                PlanDataBaseFragment.this.secondAdapter.notifyDataSetChanged();
                PlanDataBaseFragment.this.fileTextList.clear();
                PlanDataBaseFragment.this.fileImageList.clear();
                PlanDataBaseFragment.this.fileAttachmentList.clear();
                for (GetDirectoryData.DataBean.FilesBean filesBean : PlanDataBaseFragment.this.getDirectoryData.getData().getFiles()) {
                    if (filesBean.getCNUM().equals(((GetDirectoryData.DataBean.FoldersBean) PlanDataBaseFragment.this.folderList.get(i)).getCNUM())) {
                        if (filesBean.getFILETYPE().equals("文本")) {
                            PlanDataBaseFragment.this.fileTextList.add(filesBean);
                        } else if (filesBean.getFILETYPE().equals("图件")) {
                            PlanDataBaseFragment.this.fileImageList.add(filesBean);
                        }
                    }
                }
                PlanDataBaseFragment planDataBaseFragment = PlanDataBaseFragment.this;
                planDataBaseFragment.getDirsDataPopupWindow(planDataBaseFragment.fileTextList, PlanDataBaseFragment.this.fileImageList, PlanDataBaseFragment.this.fileAttachmentList, i, PlanDataBaseFragment.this.getActivity().findViewById(R.id.viewPager));
            }
        });
        this.recyclePlanFirst.setAdapter(this.firstAdapter);
        this.recyclePlanSecond.setAdapter(this.secondAdapter);
        HashMap hashMap = new HashMap();
        hashMap.put("UserId", this.userId);
        hashMap.put("DeviceKey", this.deviceId);
        ((PlanDataBasePresent) this.presenter).getDirectoryVersion(hashMap);
    }

    @Override // com.gisocn.onemap.base.BaseFragment
    protected void onInvisible() {
        PopupWindow popupWindow = this.dirsPopupWindow;
        if (popupWindow != null) {
            popupWindow.dismiss();
        }
    }

    /* JADX INFO: Access modifiers changed from: protected */
    @Override // com.gisocn.onemap.base.BaseFragment
    public PlanDataBasePresent createPresenter() {
        return new PlanDataBasePresent(this);
    }

    @Override // com.gisocn.onemap.base.BaseFragment, androidx.fragment.app.Fragment
    public void onDestroyView() {
        super.onDestroyView();
        this.unbinder.unbind();
    }

    @Override // com.gisocn.onemap.view.PlanDataBaseView
    public void getDirectoryVersionSuccess(String str) {
        L.e("getDirectoryVersionSuccess" + str);
        HashMap hashMap = new HashMap();
        hashMap.put("UserId", this.userId);
        hashMap.put("DeviceKey", this.deviceId);
        ((PlanDataBasePresent) this.presenter).getDirectoryData(hashMap);
    }

    @Override // com.gisocn.onemap.view.PlanDataBaseView
    public void getDirectoryDataSuccess(GetDirectoryData getDirectoryData) {
        this.getDirectoryData = getDirectoryData;
        this.dirList.addAll(getDirectoryData.getData().getDirs());
        L.e("getDirectoryDataSuccess" + new Gson().toJson(getDirectoryData));
        this.firstAdapter.notifyDataSetChanged();
    }

    @Override // com.gisocn.onemap.view.PlanDataBaseView
    public void getDownLoadSuccess(String str) {
        this.filesLocaList.add(str);
        this.handler.sendEmptyMessage(1);
    }

    @Override // com.gisocn.onemap.view.PlanDataBaseView
    public void getDownLoadSuccess(String str, int i) {
        this.index = i;
        this.filesLocaList.add(str);
        Message message = new Message();
        message.what = 3;
        message.arg1 = i;
        this.handler.sendMessage(message);
    }

    @OnClick({R.id.iv_back, R.id.tv_close})
    public void onViewClicked(View view) {
        int id = view.getId();
        if (id != R.id.iv_back) {
            if (id != R.id.tv_close) {
                return;
            }
            getActivity().findViewById(R.id.viewPager).setVisibility(8);
            return;
        }
        this.ivBack.setVisibility(8);
        this.recyclePlanFirst.setVisibility(0);
        this.recyclePlanSecond.setVisibility(8);
    }

    void getDirsDataPopupWindow(final ArrayList<GetDirectoryData.DataBean.FilesBean> arrayList, final ArrayList<GetDirectoryData.DataBean.FilesBean> arrayList2, final ArrayList<GetDirectoryData.DataBean.FilesBean> arrayList3, int i, View view) {
        int i2;
        this.fileList.clear();
        getLocalFiles(Constant.PLAN_DATA_BASE_PATH);
        int i3 = this.fileType;
        if (i3 == 0) {
            this.fileList.addAll(arrayList);
        } else if (i3 == 1) {
            this.fileList.addAll(arrayList2);
        }
        if (this.dirsView == null) {
            View inflate = View.inflate(getActivity(), R.layout.popup_dirs, null);
            this.dirsView = inflate;
            inflate.measure(0, 0);
            i2 = (this.width - view.getWidth()) - getActivity().findViewById(R.id.leftTools_layout).getWidth();
        } else {
            i2 = 0;
        }
        if (this.dirsPopupWindow == null && this.dirsView != null) {
            int dimensionPixelOffset = getResources().getDimensionPixelOffset(R.dimen.dp_165);
            this.dirsPopupWindow = new PopupWindow(this.dirsView, i2, -1);
            TextView textView = (TextView) this.dirsView.findViewById(R.id.tv_download_all);
            final TextView textView2 = (TextView) this.dirsView.findViewById(R.id.tv_plan_text);
            final TextView textView3 = (TextView) this.dirsView.findViewById(R.id.tv_plan_image);
            final TextView textView4 = (TextView) this.dirsView.findViewById(R.id.tv_plan_attachment);
            RecyclerView recyclerView = (RecyclerView) this.dirsView.findViewById(R.id.recycle_file);
            L.e("dirsView.getWidth()" + i2);
            L.e("itemWidth" + dimensionPixelOffset);
            recyclerView.setLayoutManager(new GridLayoutManager(getActivity(), (int) Math.floor((double) (i2 / dimensionPixelOffset))));
            CommonAdapter<GetDirectoryData.DataBean.FilesBean> commonAdapter = new CommonAdapter<GetDirectoryData.DataBean.FilesBean>(getActivity(), R.layout.item_file_package, this.fileList) { // from class: com.gisocn.onemap.ui.fragment.PlanDataBaseFragment.7
                /* JADX INFO: Access modifiers changed from: protected */
                @Override // com.gisocn.onemap.base.CommonAdapter
                public void convert(ViewHolder viewHolder, GetDirectoryData.DataBean.FilesBean filesBean, int i4) {
                    viewHolder.getView(R.id.tv_file_name).setVisibility(0);
                    viewHolder.setText(R.id.tv_file_name, ((GetDirectoryData.DataBean.FilesBean) PlanDataBaseFragment.this.fileList.get(i4)).getFILENAME());
                    viewHolder.setText(R.id.tv_file_name_szie, ((GetDirectoryData.DataBean.FilesBean) PlanDataBaseFragment.this.fileList.get(i4)).getFILESIZE() + "KB");
                    String str = PlanDataBaseFragment.this.dirPath + "/" + ((GetDirectoryData.DataBean.FoldersBean) PlanDataBaseFragment.this.folderList.get(PlanDataBaseFragment.this.secondIndex)).getNAME() + "/" + ((GetDirectoryData.DataBean.FilesBean) PlanDataBaseFragment.this.fileList.get(i4)).getFILETYPE() + "/";
                    if (PlanDataBaseFragment.this.isLocalExist(Constant.PLAN_DATA_BASE_PATH + str + ((GetDirectoryData.DataBean.FilesBean) PlanDataBaseFragment.this.fileList.get(i4)).getFILENAME())) {
                        viewHolder.setVisible(R.id.iv_download, false);
                        if (PlanDataBaseFragment.this.fileType != 0) {
                            if (PlanDataBaseFragment.this.fileType == 1) {
                                viewHolder.setVisible(R.id.iv_download_bg, true);
                                Glide.with(PlanDataBaseFragment.this.getActivity()).load(Constant.PLAN_DATA_BASE_PATH + str + ((GetDirectoryData.DataBean.FilesBean) PlanDataBaseFragment.this.fileList.get(i4)).getFILENAME()).thumbnail(0.1f).into((ImageView) viewHolder.getView(R.id.iv_download_bg));
                                return;
                            }
                            return;
                        }
                        viewHolder.setVisible(R.id.iv_download_bg, false);
                        if (!((GetDirectoryData.DataBean.FilesBean) PlanDataBaseFragment.this.fileList.get(i4)).getEXTNAME().contains("pdf")) {
                            if (!((GetDirectoryData.DataBean.FilesBean) PlanDataBaseFragment.this.fileList.get(i4)).getEXTNAME().contains("doc")) {
                                if (((GetDirectoryData.DataBean.FilesBean) PlanDataBaseFragment.this.fileList.get(i4)).getEXTNAME().contains("xls")) {
                                    viewHolder.setBackgroundRes(R.id.rl_download, R.mipmap.icon_excel);
                                    return;
                                }
                                return;
                            }
                            viewHolder.setBackgroundRes(R.id.rl_download, R.mipmap.icon_docx);
                            return;
                        }
                        viewHolder.setBackgroundRes(R.id.rl_download, R.mipmap.icon_pdf);
                        return;
                    }
                    viewHolder.setVisible(R.id.iv_download, true);
                    viewHolder.setVisible(R.id.iv_download_bg, true);
                    viewHolder.setImageResource(R.id.iv_download_bg, R.mipmap.icon_download_bg);
                    viewHolder.setImageResource(R.id.iv_download, R.mipmap.icon_download);
                    viewHolder.setBackgroundRes(R.id.rl_download, R.color.white);
                }
            };
            this.fileAdapter = commonAdapter;
            recyclerView.setAdapter(commonAdapter);
            this.fileAdapter.setOnItemClickListener(new MultiItemTypeAdapter.OnItemClickListener() { // from class: com.gisocn.onemap.ui.fragment.PlanDataBaseFragment.8
                @Override // com.gisocn.onemap.base.MultiItemTypeAdapter.OnItemClickListener
                public boolean onItemLongClick(View view2, RecyclerView.ViewHolder viewHolder, int i4) {
                    return false;
                }

                @Override // com.gisocn.onemap.base.MultiItemTypeAdapter.OnItemClickListener
                public void onItemClick(View view2, RecyclerView.ViewHolder viewHolder, int i4) {
                    String filename = ((GetDirectoryData.DataBean.FilesBean) PlanDataBaseFragment.this.fileList.get(i4)).getFILENAME();
                    String str = PlanDataBaseFragment.this.dirPath + "/" + ((GetDirectoryData.DataBean.FoldersBean) PlanDataBaseFragment.this.folderList.get(PlanDataBaseFragment.this.secondIndex)).getNAME() + "/" + ((GetDirectoryData.DataBean.FilesBean) PlanDataBaseFragment.this.fileList.get(i4)).getFILETYPE() + "/";
                    if (PlanDataBaseFragment.this.isLocalExist(Constant.PLAN_DATA_BASE_PATH + str + filename)) {
                        Intent intent = new Intent(PlanDataBaseFragment.this.getActivity(), FileBrowseActivity.class);
                        intent.putExtra(TbsVideoCacheTask.KEY_VIDEO_CACHE_PARAM_URL, "local");
                        intent.putExtra("fileUrl", Constant.PLAN_DATA_BASE_PATH + str + filename);
                        intent.putExtra("fileName", filename);
                        PlanDataBaseFragment.this.startActivity(intent);
                        return;
                    }
                    PlanDataBaseFragment.this.downLoadFile(PlanDataBaseFragment.this.appConfig.getGhcgServiceURL().getGHCGFileURL() + PlanDataBaseFragment.this.dirId + "/" + ((GetDirectoryData.DataBean.FilesBean) PlanDataBaseFragment.this.fileList.get(i4)).getCNUM() + "/" + ((GetDirectoryData.DataBean.FilesBean) PlanDataBaseFragment.this.fileList.get(i4)).getFILETYPE() + "/" + ((GetDirectoryData.DataBean.FilesBean) PlanDataBaseFragment.this.fileList.get(i4)).getFILENAME(), filename, str, false, 0);
                }
            });
            ((TextView) this.dirsView.findViewById(R.id.tv_close)).setOnClickListener(new View.OnClickListener() { // from class: com.gisocn.onemap.ui.fragment.PlanDataBaseFragment.9
                @Override // android.view.View.OnClickListener
                public void onClick(View view2) {
                    PlanDataBaseFragment.this.dirsPopupWindow.dismiss();
                }
            });
            textView2.setOnClickListener(new View.OnClickListener() { // from class: com.gisocn.onemap.ui.fragment.PlanDataBaseFragment.10
                @Override // android.view.View.OnClickListener
                public void onClick(View view2) {
                    PlanDataBaseFragment.this.fileType = 0;
                    textView2.setTextColor(ContextCompat.getColor(PlanDataBaseFragment.this.getActivity(), R.color.colorWhite));
                    textView2.setBackgroundColor(ContextCompat.getColor(PlanDataBaseFragment.this.getActivity(), R.color.colorPrimary));
                    textView3.setTextColor(ContextCompat.getColor(PlanDataBaseFragment.this.getActivity(), R.color.colorPrimary));
                    textView3.setBackgroundColor(ContextCompat.getColor(PlanDataBaseFragment.this.getActivity(), R.color.colorWhite));
                    textView4.setTextColor(ContextCompat.getColor(PlanDataBaseFragment.this.getActivity(), R.color.colorPrimary));
                    textView4.setBackgroundColor(ContextCompat.getColor(PlanDataBaseFragment.this.getActivity(), R.color.colorWhite));
                    PlanDataBaseFragment.this.fileList.clear();
                    PlanDataBaseFragment.this.fileList.addAll(arrayList);
                    PlanDataBaseFragment.this.fileAdapter.notifyDataSetChanged();
                }
            });
            textView3.setOnClickListener(new View.OnClickListener() { // from class: com.gisocn.onemap.ui.fragment.PlanDataBaseFragment.11
                @Override // android.view.View.OnClickListener
                public void onClick(View view2) {
                    PlanDataBaseFragment.this.fileType = 1;
                    textView2.setTextColor(ContextCompat.getColor(PlanDataBaseFragment.this.getActivity(), R.color.colorPrimary));
                    textView2.setBackgroundColor(ContextCompat.getColor(PlanDataBaseFragment.this.getActivity(), R.color.colorWhite));
                    textView3.setTextColor(ContextCompat.getColor(PlanDataBaseFragment.this.getActivity(), R.color.colorWhite));
                    textView3.setBackgroundColor(ContextCompat.getColor(PlanDataBaseFragment.this.getActivity(), R.color.colorPrimary));
                    textView4.setTextColor(ContextCompat.getColor(PlanDataBaseFragment.this.getActivity(), R.color.colorPrimary));
                    textView4.setBackgroundColor(ContextCompat.getColor(PlanDataBaseFragment.this.getActivity(), R.color.colorWhite));
                    PlanDataBaseFragment.this.fileList.clear();
                    PlanDataBaseFragment.this.fileList.addAll(arrayList2);
                    PlanDataBaseFragment.this.fileAdapter.notifyDataSetChanged();
                }
            });
            textView4.setOnClickListener(new View.OnClickListener() { // from class: com.gisocn.onemap.ui.fragment.PlanDataBaseFragment.12
                @Override // android.view.View.OnClickListener
                public void onClick(View view2) {
                    PlanDataBaseFragment.this.fileType = 3;
                    textView2.setTextColor(ContextCompat.getColor(PlanDataBaseFragment.this.getActivity(), R.color.colorPrimary));
                    textView2.setBackgroundColor(ContextCompat.getColor(PlanDataBaseFragment.this.getActivity(), R.color.colorWhite));
                    textView3.setTextColor(ContextCompat.getColor(PlanDataBaseFragment.this.getActivity(), R.color.colorPrimary));
                    textView3.setBackgroundColor(ContextCompat.getColor(PlanDataBaseFragment.this.getActivity(), R.color.colorWhite));
                    textView4.setTextColor(ContextCompat.getColor(PlanDataBaseFragment.this.getActivity(), R.color.colorWhite));
                    textView4.setBackgroundColor(ContextCompat.getColor(PlanDataBaseFragment.this.getActivity(), R.color.colorPrimary));
                    PlanDataBaseFragment.this.fileList.clear();
                    PlanDataBaseFragment.this.fileList.addAll(arrayList3);
                    PlanDataBaseFragment.this.fileAdapter.notifyDataSetChanged();
                }
            });
            textView.setOnClickListener(new View.OnClickListener() { // from class: com.gisocn.onemap.ui.fragment.PlanDataBaseFragment.13
                @Override // android.view.View.OnClickListener
                public void onClick(View view2) {
                    PlanDataBaseFragment.this.allDownLoadList.clear();
                    ArrayList arrayList4 = new ArrayList();
                    arrayList4.addAll(arrayList);
                    arrayList4.addAll(arrayList2);
                    Iterator it = arrayList4.iterator();
                    while (it.hasNext()) {
                        GetDirectoryData.DataBean.FilesBean filesBean = (GetDirectoryData.DataBean.FilesBean) it.next();
                        DownLoadFileInfo downLoadFileInfo = new DownLoadFileInfo();
                        String str = PlanDataBaseFragment.this.appConfig.getGhcgServiceURL().getGHCGFileURL() + PlanDataBaseFragment.this.dirId + "/" + filesBean.getCNUM() + "/" + filesBean.getFILETYPE() + "/" + filesBean.getFILENAME();
                        String str2 = PlanDataBaseFragment.this.dirPath + "/" + ((GetDirectoryData.DataBean.FoldersBean) PlanDataBaseFragment.this.folderList.get(PlanDataBaseFragment.this.secondIndex)).getNAME() + "/" + filesBean.getFILETYPE() + "/";
                        if (!PlanDataBaseFragment.this.isLocalExist(Constant.PLAN_DATA_BASE_PATH + str2 + filesBean.getFILENAME()) && (filesBean.getFILETYPE().equals("图件") || filesBean.getFILETYPE().equals("文本"))) {
                            downLoadFileInfo.setFileName(filesBean.getFILENAME());
                            downLoadFileInfo.setFileUrl(str);
                            downLoadFileInfo.setLocalPath(str2);
                            L.e("setFileName" + filesBean.getFILENAME());
                            PlanDataBaseFragment.this.allDownLoadList.add(downLoadFileInfo);
                        }
                    }
                    if (PlanDataBaseFragment.this.allDownLoadList.size() > 0) {
                        PlanDataBaseFragment.this.index = 0;
                        PlanDataBaseFragment planDataBaseFragment = PlanDataBaseFragment.this;
                        planDataBaseFragment.downLoadFile(((DownLoadFileInfo) planDataBaseFragment.allDownLoadList.get(0)).getFileUrl(), ((DownLoadFileInfo) PlanDataBaseFragment.this.allDownLoadList.get(0)).getFileName(), ((DownLoadFileInfo) PlanDataBaseFragment.this.allDownLoadList.get(0)).getLocalPath(), true, PlanDataBaseFragment.this.index);
                    }
                }
            });
        }
        this.fileAdapter.notifyDataSetChanged();
        this.dirsPopupWindow.setOutsideTouchable(false);
        this.dirsPopupWindow.setFocusable(false);
        this.dirsPopupWindow.setBackgroundDrawable(new BitmapDrawable());
        this.dirsPopupWindow.showAsDropDown(view, view.getWidth(), 0);
    }

    public void getLocalFiles(String str) {
        Log.e("path", str);
        File[] listFiles = new File(str).listFiles();
        if (listFiles == null) {
            Log.e("error", "空目录");
            return;
        }
        for (int i = 0; i < listFiles.length; i++) {
            if (listFiles[i].isDirectory()) {
                getLocalFiles(listFiles[i].getAbsolutePath());
            } else {
                this.filesLocaList.add(listFiles[i].getAbsolutePath());
            }
        }
    }

    void downLoadFile(String str, String str2, String str3, final boolean z, int i) {
        if (isLocalExist(Constant.PLAN_DATA_BASE_PATH + str3 + str2)) {
            Intent intent = new Intent(getActivity(), FileBrowseActivity.class);
            intent.putExtra(TbsVideoCacheTask.KEY_VIDEO_CACHE_PARAM_URL, "local");
            intent.putExtra("fileUrl", Constant.PLAN_DATA_BASE_PATH + str3 + str2);
            intent.putExtra("fileName", str2);
            startActivity(intent);
            return;
        }
        Dialog dialog = this.dialog;
        if (dialog != null) {
            dialog.show();
            TextView textView = this.tvFileName;
            textView.setText("正在下载\"" + str2 + Typography.quote);
            if (z) {
                TextView textView2 = this.tvIndex;
                textView2.setText((i + 1) + "  of  " + this.allDownLoadList.size());
            } else {
                this.tvIndex.setText("");
            }
        } else {
            showDialog(str2, z);
        }
        ((PlanDataBasePresent) this.presenter).getDownLoading(str, str3, str2, z, i, new DownLoadListener() { // from class: com.gisocn.onemap.ui.fragment.PlanDataBaseFragment.14
            @Override // com.gisocn.onemap.interfaces.DownLoadListener
            public void onFailure() {
            }

            @Override // com.gisocn.onemap.interfaces.DownLoadListener
            public void onStart() {
            }

            @Override // com.gisocn.onemap.interfaces.DownLoadListener
            public void onProgress(int i2) {
                Message message = new Message();
                message.what = 2;
                message.arg1 = i2;
                message.arg2 = !z ? 1 : 0;
                PlanDataBaseFragment.this.handler.sendMessage(message);
            }

            @Override // com.gisocn.onemap.interfaces.DownLoadListener
            public void onFinish(String str4) {
                L.e("localPath" + str4);
            }
        });
    }

    boolean isLocalExist(String str) {
        return this.filesLocaList.contains(str);
    }

    public void showDialog(String str, boolean z) {
        LinearLayout linearLayout = (LinearLayout) LayoutInflater.from(getActivity()).inflate(R.layout.dialog_download_progress, (ViewGroup) null);
        AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
        builder.setView(linearLayout).setCancelable(false);
        AlertDialog create = builder.create();
        this.dialog = create;
        create.show();
        this.tvIndex = (TextView) linearLayout.findViewById(R.id.tv_index);
        TextView textView = (TextView) linearLayout.findViewById(R.id.tv_file_name);
        this.tvFileName = textView;
        textView.setText("正在下载\"" + str + Typography.quote);
        if (z) {
            TextView textView2 = this.tvIndex;
            textView2.setText((this.index + 1) + "  of  " + this.allDownLoadList.size());
        }
        this.tvOff = (TextView) linearLayout.findViewById(R.id.tv_off);
        this.numberProgressBar = (NumberProgressBar) linearLayout.findViewById(R.id.number_progress_bar);
        this.tvOff.setText("取消");
        this.tvOff.setOnClickListener(new View.OnClickListener() { // from class: com.gisocn.onemap.ui.fragment.PlanDataBaseFragment.15
            @Override // android.view.View.OnClickListener
            public void onClick(View view) {
                PlanDataBaseFragment.this.dialog.dismiss();
            }
        });
    }
}
